/*
 * Created on 27/02/2004
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.potiorb.orb.receive;


import org.potiorb.orb.giop.GIOPMessageHeader;
import org.potiorb.orb.giop.GIOPMessageRequest;
import org.potiorb.orb.giop.MessageType;
import org.potiorb.orb.iiop.EndPoint;
import org.potiorb.orb.poa.POA;

public class ServiceHandle extends Thread {
	private EndPoint m_EndPoint;
	private POA _poa;

	public ServiceHandle(EndPoint pEndPoint, POA poa){
		this.m_EndPoint = pEndPoint;
		this._poa = poa;
	}

	public void run(){
		while(true)
		{
                     try{
                       GIOPMessageHeader msg = (GIOPMessageHeader)this.m_EndPoint.Receive();
                       if (msg.getM_MessageType().value() == MessageType.REQUEST) {
                         GIOPMessageRequest msgReq = (GIOPMessageRequest) msg;
                         this.m_EndPoint.Send(_poa.Dispatch(msgReq));
                       }
                     }catch (java.net.SocketException e){
                        break;
                     }

		}
	}

}
